package com.tan.androidtest.launchactivity;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.TextView;

import com.tan.androidtest.R;
import com.tan.androidtest.base.BaseActivity;

/**
 * 测试显示  隐式启动activity
 */

public class TestLaunchActivity extends BaseActivity implements View.OnClickListener {

    @Override
    public int initLayoutId() {
        return R.layout.activity_test_launch_activity_layout;
    }

    @Override
    public void initTitle(TextView tv_bar_left, TextView tv_bar_title, TextView tv_bar_right) {
        tv_bar_title.setText("测试显示隐式启动Activity");
    }

    @Override
    public void initView() {
        TextView tv_test = findViewById(R.id.tv_test);
        tv_test.setOnClickListener(this);
    }

    @Override
    public void initData() {

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_test: {
                launchActivityByImplicit();
                break;
            }
        }
    }

    /**
     * 隐式启动OtherActivity
     */
    private void launchActivityByImplicit() {
        PackageManager manager = getPackageManager();
        Intent intent = new Intent();
        intent.setAction("com.tan.androidtest.launchactibity.other");
        startActivity(intent);
        if (manager.resolveActivity(intent, 0) != null) {//利用PackageManager的resolveActivity判断应用是否有这个activity
            startActivity(intent);
        }
        if (intent.resolveActivity(getPackageManager()) != null) {//利用Intent的resolveActivity判断应用是否有这个activity
            startActivity(intent);
        }

    }


}
